<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="com.shopcart.entity.*"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet"
	media="screen" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>

<title>BOUN SHOP</title>
</head>
<body>
	<div class="navbar navbar-inverse">
		<div class="navbar-inner">
			<a class="brand" href="home.jsp">BOUN SHOP</a>
			<ul class="nav">
				<li class="active"><a href="home.jsp">Home</a></li>
				<!-- 
				 -->
				<li><a href="cart.jsp">My Cart</a></li>
				<li><a href="history.jsp">My History</a></li>
			</ul>
			<ul class="nav pull-right">
				<li><button type="button" class="btn btn-success" onclick="">Checkout</button></li>
				<li class="divider-vertical"></li>
				<li><button type="button" class="btn btn-danger" onclick="logout();">Log Out</button></li>
			</ul>
		</div>
	</div>

	<div class="container">
		<div class="hero-unit">
			<h2>Greetings ${customer.firstName}</h2>
			
			<c:forEach var="p" items="${customer.productsNotInStock}">
				<c:if test = "${p.quantity != 0}">
					<div><i pId="${p.id}" class="icon-remove"></i>Now, ${p.name} is in stock!</div>
					<br/>
				</c:if>
			</c:forEach>
		</div>
	</div>
	
	<script type="text/javascript">
		function logout () {
		    var form = document.createElement('form');
		    form.setAttribute('method', 'post');
		    form.setAttribute('action', 'logout');
		    form.style.display = 'hidden';
		    document.body.appendChild(form);
		    form.submit();
		}
		
		$(".icon-remove").click(function() {
			var productId = $(this).attr("pId");
			
			$.ajax({
				url : "/ShoppingCartWeb/ProductServlet",
				type : "POST",
				data : {productId : productId},
				success : function(data) {
					location.reload();
				},
				error : function(data) {
					alert('error removing product from warn list');
				}
			});
		});
	</script>
</body>
</html>